package ngamejava2;

public class GameSpeedTracker
{
	static public double NANOS_IN_ONE_SECOND = 1e9;
	protected int ticksPerSecond;
	protected int framesPerSecond;
	protected long previousNanotime;
	protected int countedTicks;
	protected int totalTicks;
	protected int countedFrames;
	protected int totalFrames;
	protected int idleLoopsPerSecond;
	protected int countedIdleLoops;

	public void start()
	{
		previousNanotime = System.nanoTime();
		countedTicks = 0;
		countedFrames = 0;
		countedIdleLoops = 0;
		ticksPerSecond = 0;
		framesPerSecond = 0;
		idleLoopsPerSecond = 0;
		totalTicks = 0;
		totalFrames = 0;
	}

	public int countTick()
	{
		countedTicks++;
		totalTicks++;
		return totalTicks;
	}

	public int countFrame()
	{
		countedFrames++;
		totalFrames++;
		return totalFrames;
	}

	public void countIdleLoop()
	{
		countedIdleLoops++;
	}

	protected void update()
	{
		if (System.nanoTime() - previousNanotime > NANOS_IN_ONE_SECOND)
		{
			ticksPerSecond = countedTicks;
			framesPerSecond = countedFrames;
			idleLoopsPerSecond = countedIdleLoops;
			countedTicks = 0;
			countedFrames = 0;
			countedIdleLoops = 0;
			previousNanotime = System.nanoTime();
		}
	}

	public int getTPS()
	{
		return ticksPerSecond;
	}

	public int getTotalTicks()
	{
		return totalTicks;
	}

	public int getFPS()
	{
		return framesPerSecond;
	}

	public int getTotalFrames()
	{
		return totalFrames;
	}

	public int getIdleLoopsPerSecond()
	{
		return idleLoopsPerSecond;
	}
}